package com.jyw.business.obstacles.controller;

import com.jyw.business.obstacles.constant.OrderSourceConstant;
import com.jyw.business.obstacles.domain.dto.web.OrderAddDto;
import com.jyw.business.obstacles.domain.dto.web.OrderReminderDto;
import com.jyw.business.obstacles.domain.dto.web.OrderRepairPageDto;
import com.jyw.business.obstacles.domain.dto.web.OrderTerminationDto;
import com.jyw.business.obstacles.domain.dto.wechat.EvaluateOrderDto;
import com.jyw.business.obstacles.domain.vo.web.OrderRepairPageVO;
import com.jyw.business.obstacles.service.IObsOrderFaultService;
import com.jyw.business.obstacles.service.IObsOrderMakeService;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.utils.ip.IpUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author Created by ZhangCheng on 2024/01/17
 */
@Api(tags = "报修管理")
@RestController
@RequestMapping("/obstacles/repair")
public class ObsRepairController extends BaseController {

    @Resource
    private IObsOrderMakeService iObsOrderMakeService;

    @Resource
    private IObsOrderFaultService orderFaultService;

    /**
     * 分页查询报修管理列表
     *
     * @param pageDto
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页查询报修管理列表")
    @PreAuthorize("@ss.hasPermi('obs:repair:list')")
    public TableDataInfo<OrderRepairPageVO> page(OrderRepairPageDto pageDto) {
        return getDataTable(iObsOrderMakeService.repairPage(pageDto));
    }

    /**
     * 获取报修电脑IP地址
     *
     * @return
     */
    @GetMapping(value = "/getIpAddress")
    @ApiOperation("获取报修电脑IP地址")
    public CommonResult<String> getIpAddress() {
        return CommonResult.success("操作成功",IpUtils.getIpAddr());
    }

    /**
     * 创建报修
     *
     * @param addDto
     * @return
     */
    @PostMapping("addRepairOrder")
    @ApiOperation("创建报修")
    @PreAuthorize("@ss.hasPermi('obs:repair:add')")
    public CommonResult addRepairOrder(@RequestBody OrderAddDto addDto) {
        addDto.setSource(OrderSourceConstant.PC);
        orderFaultService.add(addDto);
        return CommonResult.success();
    }

    /**
     * 工单评价
     *
     * @param dto
     * @return
     */
    @PostMapping("/evaluate")
    @ApiOperation("工单评价")
    @PreAuthorize("@ss.hasPermi('obs:repair:evaluate')")
    public CommonResult evaluate(@RequestBody @Valid EvaluateOrderDto dto) {
        iObsOrderMakeService.evaluate(dto);
        return CommonResult.success();
    }

    /**
     * 工单终止
     *
     * @param orderDto
     * @return
     */
    @PutMapping("/termination")
    @ApiOperation("工单终止")
    @PreAuthorize("@ss.hasPermi('obs:repair:termination')")
    public CommonResult termination(@RequestBody @Valid OrderTerminationDto orderDto) {
        iObsOrderMakeService.termination(orderDto);
        return CommonResult.success();
    }

    /**
     * 工单催单
     *
     * @param orderReminderDto
     * @return
     */
    @PutMapping("/reminder")
    @ApiOperation("工单催单")
    @PreAuthorize("@ss.hasPermi('obs:repair:reminder,obstacles:server:reminder')")
    public CommonResult reminder(@RequestBody @Valid OrderReminderDto orderReminderDto) {
        iObsOrderMakeService.reminder(orderReminderDto);
        return CommonResult.success();
    }
}
